﻿using System;
using System.Collections.Generic;
using System.Text;


// 重写  Equals
// https://blog.csdn.net/shenmegui_zyf/article/details/51685195

namespace MyMath
{
    public struct Vector2
    {
        public float x;
        public float y;

        public Vector2(float px = 0, float py = 0)
        {
            x = px;
            y = py;
        }

        public Vector2(Vector2 other)
        {
            x = other.x;
            y = other.y;
        }

        public override string ToString()
        {
            return $"{x}\t{y}";
        }

        public bool Equals(Vector2 obj)
        {
            // test obj is null
            if (ReferenceEquals(this, obj))
            {
                return true;
            }
            return Mathf.Eq(x, obj.x) && Mathf.Eq(y, obj.y);
        }


        public static Vector2 operator +(Vector2 lhs, Vector2 rhs)
        {
            return new Vector2(lhs.x + rhs.x, lhs.y + rhs.y);
        }

        public static Vector2 operator +(Vector2 lhs)
        {
            return new Vector2(lhs); ;
        }

        public static Vector2 operator -(Vector2 lhs)
        {
            return new Vector2(-lhs.x, -lhs.y);
        }
        public static Vector2 operator -(Vector2 lhs, Vector2 rhs)
        {
            return new Vector2(lhs.x - rhs.x, lhs.y - rhs.y);
        }

        //public static bool operator ==(Vector2 lhs, Vector2 rhs)
        //{
        //    return lhs.Equals(rhs);
        //}
        //public static bool operator !=(Vector2 lhs, Vector2 rhs)
        //{
        //    return !lhs.Equals(rhs);
        //}

        // TODO:  += -= *= /= 

    }
}
